<template>
  <div class="tabControl">
    <div v-for="(item,index) in titles" :key="index" 
    class="tabControlItem" :class="{active: index == currentIndex}" @click="itemClick(index)">
      <span>{{ item }}</span>
    </div>
  </div>
</template>

<script>

export default {
  name:'TabControl',
  props: {
    titles: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  data() {
    return {
      currentIndex: 0
    }
  },
  methods: {
    itemClick(index) {
      this.currentIndex = index;
      this.$emit('tabClick',index);
    }
  }
}
</script>

<style scoped>
  .tabControl {
    display: flex;
    text-align: center;
  }
  .tabControlItem {
    flex: 1;
    height: 40px;
    line-height: 40px;
    font-size: 15px;
    background-color: rgb(199, 166, 166);
  }
  .tabControlItem span {
    padding: 2px;
  }
  .active {
    color: hotpink;
  }
  .active span {
    border-bottom: 2px solid hotpink;
  }
</style>